import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isUndefined from "lodash/isUndefined";

var _dec, _dec2, _class, _class2;

import React from 'react';
import { Form, Icon, Input, InputNumber, Modal, Select, Tooltip } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
import Lov from 'components/Lov';
import { CODE_UPPER } from 'utils/regExp';
var FormItem = Form.Item;
var TextArea = Input.TextArea;
var formLayout = {
  labelCol: {
    span: 6
  },
  wrapperCol: {
    span: 16
  }
};
var JobGroupForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(JobGroupForm, _React$PureComponent);

  var _super = _createSuper(JobGroupForm);

  function JobGroupForm() {
    _classCallCheck(this, JobGroupForm);

    return _super.apply(this, arguments);
  }

  _createClass(JobGroupForm, [{
    key: "onOk",
    value: function onOk() {
      var _this$props = this.props,
          onOk = _this$props.onOk,
          form = _this$props.form;
      form.validateFields(function (error, fieldsValue) {
        if (!error) {
          onOk(fieldsValue);
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          form = _this$props2.form,
          initData = _this$props2.initData,
          modalVisible = _this$props2.modalVisible,
          modalTitle = _this$props2.modalTitle,
          saving = _this$props2.saving,
          creating = _this$props2.creating,
          onCancel = _this$props2.onCancel;
      var getFieldDecorator = form.getFieldDecorator,
          getFieldValue = form.getFieldValue;
      var executorCode = initData.executorCode,
          orderSeq = initData.orderSeq,
          addressList = initData.addressList,
          executorId = initData.executorId,
          executorName = initData.executorName,
          executorType = initData.executorType,
          serverName = initData.serverName;
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        title: modalTitle,
        visible: modalVisible,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        confirmLoading: executorId ? saving : creating,
        onCancel: onCancel,
        onOk: this.onOk
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('csdr.jobGroup.view.message.orderSeq').d('排序')
      }), getFieldDecorator('orderSeq', {
        initialValue: orderSeq,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('csdr.jobGroup.view.message.orderSeq').d('排序')
          })
        }, {
          pattern: /^(-(100|[1-9][0-9]?)|([1-9][0-9]{0,1}|100)|0)$/,
          message: intl.get('csdr.jobGroup.view.message.seqRule').d('取值范围为-100~100')
        }]
      })( /*#__PURE__*/React.createElement(InputNumber, {
        min: -100,
        max: 100,
        step: 1,
        style: {
          width: '100%'
        }
      }))), /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('csdr.jobGroup.view.message.executorCode').d('执行器编码')
      }), getFieldDecorator('executorCode', {
        initialValue: executorCode,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('csdr.jobGroup.view.message.executorCode').d('执行器编码')
          })
        }, {
          pattern: CODE_UPPER,
          message: intl.get('cpaas.common.validation.codeUpper').d('全大写及数字，必须以字母、数字开头，可包含“-”、“_”、“.”、“/”')
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        typeCase: "upper",
        inputChinese: false,
        disabled: !_isUndefined(executorId)
      }))), /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('csdr.jobGroup.view.message.executorName').d('执行器名称')
      }), getFieldDecorator('executorName', {
        initialValue: executorName,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('csdr.jobGroup.view.message.executorName').d('执行器名称')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('csdr.jobGroup.view.message.addressType').d('注册方式')
      }), getFieldDecorator('executorType', {
        initialValue: executorType === 1 ? 1 : 0,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('csdr.jobGroup.view.message.addressType').d('注册方式')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, {
        style: {
          width: '100%'
        },
        disabled: !_isUndefined(executorId)
      }, /*#__PURE__*/React.createElement(Select.Option, {
        value: 0
      }, intl.get('csdr.jobGroup.view.message.auto').d('自动注册')), /*#__PURE__*/React.createElement(Select.Option, {
        value: 1
      }, intl.get('csdr.jobGroup.view.message.byHand').d('手动录入'))))), getFieldValue('executorType') === 1 ? /*#__PURE__*/React.createElement(FormItem // label={intl.get('csdr.jobGroup.view.message.addressList').d('机器地址')}
      , Object.assign({
        label: /*#__PURE__*/React.createElement("span", null, intl.get('csdr.jobGroup.view.message.addressList').d('机器地址'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('csdr.jobGroup.view.message.addressList.help.msg').d('多个机器地址用逗号隔开')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        })))
      }, formLayout), getFieldDecorator('addressList', {
        initialValue: addressList,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('csdr.jobGroup.view.message.addressList').d('机器地址')
          })
        }]
      })( /*#__PURE__*/React.createElement(TextArea, {
        rows: 3,
        disabled: executorType === 0
      }))) : /*#__PURE__*/React.createElement(FormItem, Object.assign({}, formLayout, {
        label: intl.get('csdr.jobGroup.view.message.serverName').d('服务')
      }), getFieldDecorator('serverName', {
        initialValue: serverName,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get('csdr.jobGroup.view.message.serverName').d('服务')
          })
        }]
      })( /*#__PURE__*/React.createElement(Lov, {
        allowClear: false,
        code: "CADM.ROUTE.SERVICE_CODE",
        textValue: serverName
      }))));
    }
  }]);

  return JobGroupForm;
}(React.PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "onOk", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "onOk"), _class2.prototype)), _class2)) || _class);
export { JobGroupForm as default };